// pages/account/bank/bank.js
let common = require('../../../utils/common');
Page({
  data: {
    screenWidth: 0,
    screenHeight: 0,
    banks: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.registerEvent();
    this.reqBanks();
  },
  registerEvent() {
    // this.maskSize();
  },
  maskSize() {
    let that = this;
    wx.getSystemInfo({
      success(res) {
        if (res.screenWidth) {
          that.setData({
            screenWidth: res.screenWidth,
            screenHeight: res.screenHeight
          });
        } else {
          that.setData({
            screenWidth: res.windowWidth,
            screenHeight: res.windowHeight
          });
        }
      }
    })
  },
  reqBanks() {
    let that = this;
    common.asynPost(common.API.user.cards, {}, (data) => {
      if (data['cards']) {
        that.setData({
          banks: data['cards']
        });
      }
    });
  },
  newBank(){
    wx.navigateTo({
      url: '../bankcard/bankcard'
    })
  },
  editBank(e){
    let that = this,id = e.currentTarget.dataset.id;
    let bank = this.data.banks.filter((b)=>{
      return b.id = id;
    });
    wx.navigateTo({
      url:'../bankcard/bankcard?info=' + JSON.stringify(bank[0])
    });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})